/// @file Particle.cpp
/// @brief the unit particle used to represent the mass and all of its properties

#include "Particle.h"

Particle::Particle
            (
                const int _id,
                const float _mass,
                const bool _moveable
            )
{
    //init params
    m_id = _id;
    m_mass = _mass;

    m_position = 0;
    m_velocity = 0;

    m_lastLastPosition = 0;
    m_lastPosition = 0;

    m_lastVelocity = 0;

    m_initialPosition = 0;

    m_netForce = 0;

    m_moveable = _moveable;

    //init neighbours to an empty list
    m_neighbourList = new std::vector<Spring*>;
}

Particle::~Particle()
{
    //delete all spring objects in the list and clear the list
    for (int i = 0; i < m_neighbourList->size(); i++) delete (*m_neighbourList)[i];
    delete m_neighbourList;
}

void Particle::setPosition(const ngl::Vector _p)
{
    //set position to new value
    m_lastLastPosition = _p;
    m_lastPosition = _p;
    m_position = _p;
}

void Particle::updatePosition(const ngl::Vector _p)
{
    //save last value
    m_lastLastPosition = m_lastPosition;

    //save current value
    m_lastPosition = m_position;

    //update to new value
    m_position = _p;
}

void Particle::setVelocity(const ngl::Vector _v)
{
    //save current value
    m_lastVelocity = m_velocity;

    //update to new value
    m_velocity = _v;
}

Particle Particle::clone()
{
    Particle p;
    p.m_id = m_id;
    p.m_initialPosition = m_initialPosition;
    p.m_lastLastPosition = m_lastLastPosition;
    p.m_lastPosition = m_lastPosition;
    p.m_lastVelocity = m_lastVelocity;
    p.m_mass = m_mass;
    p.m_moveable = m_moveable;
    p.m_position = m_position;
    p.m_velocity = m_velocity;

    return p;
}

